home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
enviro.zip
/
ENVIRON.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-01-04
|
3KB
|
101 lines
{
Turbo Pascal Ver 4.0 Unit
Written Dec 1, 1987
Programmer: Bob Landry 73300,1717
This Unit is used for reading the environment passed to a program. The
variable 'EnvCount' will contain the total number of environment variables
passed while 'RunFile' is a string containing the complete drive, path,
and filename specification for the program which is using this unit.
The function 'EnvironStr' will return an environment variable string for
'StrNo'. 'StrNo' must be in the range 1 to 'EnvCount' otherwise 'EnvironStr'
returns a NULL string.
}
Unit Environ;
Interface
Var
EnvCount : Integer;
RunFile : String;
Function EnvironStr(StrNo : Integer) : String;
Implementation
Var
EnvBase : ^Word;
EnvPtr : ^Char;
Environment : String;
ZeroCount : Integer;
CharsCnt : Integer;
L : Integer;
Function EnvironStr( StrNo : Integer ) : String;
begin
If (StrNo < 1) or (StrNo > EnvCount) then
begin
EnvironStr := '';
exit
end;
Dec(StrNo);
EnvBase := Ptr(PrefixSeg,$2C);
CharsCnt := 0;
While StrNo <> 0 do
begin
EnvPtr := Ptr(EnvBase^,CharsCnt);
While EnvPtr^ <> #0 do
begin
EnvPtr := Ptr(EnvBase^,CharsCnt);
Inc(CharsCnt)
end;
Dec(StrNo)
end;
L := 0;
EnvPtr := Ptr(EnvBase^,CharsCnt);
While EnvPtr^ <> #0 do
begin
Inc(L);
EnvironStr[L] := EnvPtr^;
Inc(CharsCnt);
EnvPtr := Ptr(EnvBase^,CharsCnt);
end;
EnvironStr[0] := chr(L);
end; { End Function EnvironStr }
Begin
ZeroCount := 0;
EnvBase := Ptr(PrefixSeg,$2C);
EnvCount := 0;
L := 0;
CharsCnt := 0;
While ZeroCount < 2 do
begin
EnvPtr := Ptr(EnvBase^,CharsCnt);
While EnvPtr^ <> #0 do
begin
ZeroCount := 0;
Inc(CharsCnt);
EnvPtr := Ptr(EnvBase^,CharsCnt);
end;
If ZeroCount = 0 then
Inc(EnvCount);
Inc(ZeroCount);
Inc(CharsCnt);
end;
Inc(CharsCnt,2);
EnvPtr := Ptr(EnvBase^,CharsCnt);
While EnvPtr^ <> #0 do
begin
Inc(L);
RunFile[L] := EnvPtr^;
Inc(CharsCnt);
EnvPtr := Ptr(EnvBase^,CharsCnt);
end;
RunFile[0] := chr(L);
end. { End Unit Environ }